#include <struct.h>
#include <termios.h>

void serial_init(int fd)
{
	struct termios options;
	tcgetattr(fd,&options);
	options.c_cflag |= (CLOCAL | CREAD);
	options.c_cflag &= ~CSIZE;
	options.c_cflag &= ~CRTSCTS;
	options.c_cflag |= CS8;
	options.c_cflag &= ~CSTOPB;
	options.c_iflag |= IGNPAR;
	options.c_iflag &= ~(ICRNL | IXON);
	options.c_oflag = 0;
	options.c_lflag = 0;

	cfsetispeed(&options,B115200);
	cfsetospeed(&options,B115200);
	tcsetattr(fd,TCSANOW,&options);
}

float dota_atof(char unitl)
{
	if(unitl >100)
	{
		return unitl / 1000.0;
	}
	else if(unitl > 10)
	{
		return unitl / 100.0;
	}
	else
	{
		return unitl / 10.0;
	}
}

int dota_atoi(const char *cDecade)
{
	int result = 0;
	if(' ' != cDecade[0])
	{
		result = (cDecade[0] - 48)*10;
	}
	result += cDecade[1] - 48;
	return result;
}

float dota_adc(unsigned int ratio)
{
	return ((ratio * 3.3)/1024);
}

void m0_review()
{
  struct msg_struct send;
  cJSON *object = cJSON_CreateObject();
	cJSON_AddItemToObject(object,"type",cJSON_CreateNumber(2));
	cJSON_AddItemToObject(object,"result",cJSON_CreateNumber(0));
	cJSON_AddItemToObject(object,"msg",cJSON_CreateString("控制成功"));
	strcpy(send.msg_val,cJSON_Print(object));
	send.key=10;
	if(msg_queue_send("msg_report",&send,sizeof(send),0)<0)
	{
		printf("send error\n");
	}
	printf("%s\n",send.msg_val);
}
